# https://leetcode.cn/problems/largest-number/
# 给定一组非负整数 nums，重新排列每个数的顺序（每个数不可拆分）使之组成一个最大的整数。
from typing import List
class Solution:
    def largestNumber(self, nums: List[int]) -> str:
        s = ""
        num = []
        # 将数字转换成字符串
        for i in nums:
            num.append(str(i))
        for i in range(len(num)-1):
            for j in range(len(num)-1-i):
                # 进行字符串拼接比较
                if num[j]+num[j+1] < num[j+1]+num[j]:
                    num[j],num[j+1] = num[j+1],num[j]
        result = ''.join(num)
        # 以0开头，最大就是0
        if result.startswith('0'):
            return 0
        return result

sl = Solution()
print(sl.largestNumber([2,9,5,10]))
